package com.northwind.serviceImpl;

import com.northwind.dao.LogMapper;
import com.northwind.entity.Log;
import com.northwind.entity.LogExample;
import com.northwind.entity.User;
import com.northwind.entity.UserExample;
import com.northwind.service.LogService;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Service
public class LogServiceImpl implements LogService {
    @Resource
    LogMapper logMapper;

    @Override
    public HashMap<String, Object> queryAllPage(Integer page, Integer rows) {
        HashMap<String, Object> map = new HashMap<>();
        //前台接收的参数 page当前页 rows每页展示的数据量
        //后台返回 page当前页 records总条数 total总页数 rows数据集合
        map.put("page",page);
        //创建条件对象
        LogExample logExample = new LogExample();
        //总条数
        int records = logMapper.selectCountByExample(logExample);
        map.put("records",records);
        //总页数=总条数/每页展示条数，除不尽+1
        int total = records % rows == 0 ?records/rows:records/rows+1;
        map.put("total",total);
        //分页查询数据  1.条件 2.分页对象
        List<Log> logs = logMapper.selectByExampleAndRowBounds(logExample, new RowBounds((page - 1) * rows, rows));
        map.put("rows",logs);
        return map;

    }
}
